package com.ruoyi.web.controller.liangshi;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.liangshi.domain.ArchItemClass;
import com.ruoyi.liangshi.service.IArchItemClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author LiuJin
 * @Date: Create in 2023-11-14 14:07
 * @Description: this class is
 */
@RestController
@RequestMapping("/liangshi/archItemClass")
public class ArchItemClassController extends BaseController {

    @Autowired
    private IArchItemClassService archItemClassService;

    /**
     * 获取菜品分类树形图
     * @return
     */
    @GetMapping("/archItemClassSelectList")
    public AjaxResult getArchItemClassSelectList(){
        AjaxResult ajaxResult = AjaxResult.success();
        List<ArchItemClass> archItemClassSelectList = archItemClassService.getArchItemClassSelectList();
        List<Tree<String>> treeList = TreeUtil.build(archItemClassSelectList, "0", (bean, node) -> {
            node.putExtra("code", bean.getCode());
            node.setParentId(String.valueOf(bean.getPid()));
            node.setId(String.valueOf(bean.getId()));
            node.setName(bean.getName());
        });
        ajaxResult.put("archItemList",treeList);
        return ajaxResult;
    }


}
